package index;

import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/LogoutServlet")
public class LogoutServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        // 获取会话对象，若不存在则不创建新会话
        HttpSession session = request.getSession(false);
        if (session != null) {
            // 销毁会话，清空所有属性
            session.invalidate();
        }
        // 重定向到登录页面
        response.sendRedirect("loginRegister.jsp");
    }
}
